/******************************************************************************

    Copyright (C) 2006 Alessio Stalla (alessiostalla@gmail.com)

    This file is part of PrettyProlog.

    PrettyProlog is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    PrettyProlog is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PrettyProlog; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

    See the file COPYING for further details.

 *****************************************************************************/

package prettyprolog.gui;

/**
 * @author Alessio Stalla Common superclass of every PrettyProlog panel.<br />
 *         It's not abstract and thus can be used like a JPanel, altough often
 *         to obtain a PrettyProlog-aware behaviour it'll need to be subclassed
 *         to override some of its methods.
 */
public class PrettyPrologPanel extends javax.swing.JPanel {

	private static final long serialVersionUID = 1L;

	/**
	 * Controls whether this panel should display variables intended to be
	 * hidden from the user, such as temporary ones.
	 */
	protected boolean show_hidden_variables = false;

	/**
	 * A name identifying this panel. The name can be showed to the user by a
	 * PrettyPrologApplet when this panel is added to it, for example in the
	 * form of a tabbed pane label.
	 */
	protected String name = null;

	/** The PrettyPrologApplet this panel is added to. */
	protected PrettyPrologApplet owner = null;

	/** Creates a new panel with a default name. */
	public PrettyPrologPanel() {
		this("Generic PrettyProlog Panel");
	}

	/** Creates a new panel with the specified name. */
	public PrettyPrologPanel(String name) {
		super();
		this.name = name;
	}

	/**
	 * Sets the owner of this panel, useful if this panel needs to add menus or
	 * other elements to its owner. If already owned by a PrettyPrologApplet,
	 * this panel is removed from it first using the removeFromOwner method.<br />
	 * This method is called by the PrettyPrologApplet.addPanel() method.
	 */
	protected void setOwner(PrettyPrologApplet p) {
		if (owner != null)
			removeFromOwner();
		owner = p;
	}

	/**
	 * Notifies this panel that it no longer belongs to a PrettyPrologApplet and
	 * so it must remove what it added to it, like additional menus/menu items,
	 * listeners, etc.
	 */
	protected void removeFromOwner() {
		owner = null;
	}

	/**
	 * Controls whether hidden variables are to be shown to the user.
	 */
	public void showHiddenVariables(boolean show) {
		show_hidden_variables = show;
	}

	/** @return the name of this panel. */
	public String getName() {
		return name;
	}

}
